<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>📊 智能财务分析 - 预算管理系统</title>
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/notification.css">
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
    <style>
        /* 健康评分卡片样式 */
        .health-score-card {
            text-align: center;
            padding: 40px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 15px;
            margin-bottom: 30px;
            box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
        }

        .score-circle {
            width: 200px;
            height: 200px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.2);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 60px;
            font-weight: bold;
            margin: 20px 0;
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
        }

        .score-level {
            font-size: 24px;
            margin-top: 10px;
            font-weight: 600;
        }

        .score-dimensions {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            gap: 15px;
            margin-top: 30px;
        }

        .dimension-card {
            background: rgba(255, 255, 255, 0.15);
            padding: 20px;
            border-radius: 10px;
            backdrop-filter: blur(10px);
        }

        .dimension-card h4 {
            margin: 0 0 10px 0;
            font-size: 16px;
            opacity: 0.9;
        }

        .dimension-card p {
            margin: 0;
            font-size: 24px;
            font-weight: bold;
        }

        /* 异常列表样式 */
        .anomaly-list {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .anomaly-item {
            padding: 20px;
            margin: 15px 0;
            border-left: 5px solid #f44336;
            background: #fff3f3;
            border-radius: 8px;
            transition: all 0.3s;
        }

        .anomaly-item:hover {
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            transform: translateX(5px);
        }

        .anomaly-item.severity-medium {
            border-color: #ff9800;
            background: #fff8e1;
        }

        .anomaly-item.severity-low {
            border-color: #2196F3;
            background: #e3f2fd;
        }

        .anomaly-item .anomaly-title {
            font-weight: bold;
            font-size: 16px;
            margin-bottom: 8px;
            color: #333;
        }

        .anomaly-item .anomaly-meta {
            font-size: 13px;
            color: #666;
            margin: 10px 0;
        }

        .anomaly-item .anomaly-actions {
            margin-top: 12px;
        }

        .anomaly-item .anomaly-actions button {
            margin-right: 10px;
            padding: 6px 16px;
            font-size: 14px;
        }

        /* 建议卡片样式 */
        .suggestion-card {
            padding: 20px;
            margin: 15px 0;
            border-radius: 10px;
            background: white;
            border-left: 5px solid #4CAF50;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        }

        .suggestion-card.priority-high {
            border-color: #f44336;
            background: #fff3f3;
        }

        .suggestion-card.priority-medium {
            border-color: #ff9800;
            background: #fff8e1;
        }

        .suggestion-card h4 {
            margin: 0 0 10px 0;
            font-size: 18px;
            color: #333;
        }

        .suggestion-card p {
            margin: 0;
            white-space: pre-line;
            line-height: 1.6;
            color: #666;
        }

        /* 图表容器 */
        .chart-container {
            height: 400px;
            margin: 20px 0;
            background: white;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        }

        /* 分段卡片 */
        .section-card {
            background: #f8f9fa;
            border-radius: 12px;
            padding: 25px;
            margin-bottom: 25px;
            box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
        }

        .section-card h3 {
            margin: 0 0 20px 0;
            font-size: 22px;
            color: #333;
            padding-bottom: 12px;
            border-bottom: 2px solid #e0e0e0;
        }

        /* 加载状态 */
        .loading {
            text-align: center;
            padding: 60px 20px;
            color: #999;
        }

        .loading::before {
            content: "⏳";
            display: block;
            font-size: 48px;
            margin-bottom: 15px;
        }

        /* 空状态 */
        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: #999;
        }

        .empty-state::before {
            content: "📊";
            display: block;
            font-size: 64px;
            margin-bottom: 15px;
        }

        /* 返回按钮 */
        .back-button {
            position: fixed;
            top: 20px;
            left: 20px;
            background: white;
            border: none;
            padding: 10px 20px;
            border-radius: 8px;
            cursor: pointer;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
            font-size: 16px;
            transition: all 0.3s;
            z-index: 1000;
        }

        .back-button:hover {
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
            transform: translateY(-2px);
        }

        /* 时间选择器 */
        .time-selector {
            margin-bottom: 20px;
            display: flex;
            gap: 15px;
            align-items: center;
            flex-wrap: wrap;
        }

        .time-selector label {
            font-weight: 600;
            color: #555;
        }

        .time-selector input {
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 14px;
        }

        .time-selector button {
            padding: 8px 20px;
            background: #4CAF50;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s;
        }

        .time-selector button:hover {
            background: #45a049;
        }
    </style>
</head>
<body>
    <button class="back-button" onclick="window.location.href='index.html'">
        ⬅️ 返回主页
    </button>

    <div class="container" style="margin-top: 80px;">
        <h1 style="text-align: center; color: #333; margin-bottom: 30px;">
            📊 智能财务分析中心
        </h1>

        <!-- 时间选择器 -->
        <div class="section-card">
            <div class="time-selector">
                <label>分析时间范围：</label>
                <input type="date" id="startDate">
                <label>至</label>
                <input type="date" id="endDate">
                <button onclick="loadAnalysisData()">🔍 分析</button>
                <button onclick="setQuickRange('month')">本月</button>
                <button onclick="setQuickRange('3months')">近3个月</button>
                <button onclick="setQuickRange('year')">本年</button>
            </div>
        </div>

        <!-- 消费模式总结（新增） -->
        <div class="section-card" id="consumptionSummarySection" style="display: none;">
            <h3>📝 消费模式总结</h3>
            <div id="consumptionInsights" style="display: grid; gap: 15px; margin-top: 20px;">
                <!-- 动态填充洞察卡片 -->
            </div>
        </div>

        <!-- 财务健康评分 -->
        <div class="health-score-card" id="healthScoreCard">
            <h2 style="margin: 0 0 10px 0;">💯 财务健康度评分</h2>
            <div class="score-circle" id="totalScore">--</div>
            <p class="score-level" id="scoreLevel">正在计算...</p>
            
            <div class="score-dimensions">
                <div class="dimension-card">
                    <h4>💰 储蓄率</h4>
                    <p id="savingScore">-- / 30</p>
                </div>
                <div class="dimension-card">
                    <h4>📊 合理性</h4>
                    <p id="rationalityScore">-- / 30</p>
                </div>
                <div class="dimension-card">
                    <h4>🎯 执行力</h4>
                    <p id="executionScore">-- / 20</p>
                </div>
                <div class="dimension-card">
                    <h4>📈 稳定性</h4>
                    <p id="stabilityScore">-- / 20</p>
                </div>
            </div>
        </div>

        <!-- 改进建议 -->
        <div class="section-card">
            <h3>💡 改进建议</h3>
            <div id="suggestions">
                <div class="loading">正在生成建议...</div>
            </div>
        </div>

        <!-- 异常消费检测 -->
        <div class="section-card">
            <h3>⚠️ 异常消费检测</h3>
            <ul class="anomaly-list" id="anomalyList">
                <li class="loading">正在检测异常...</li>
            </ul>
        </div>

        <!-- 消费习惯分析 -->
        <div class="section-card">
            <h3>📈 消费习惯分析</h3>
            
            <h4 style="margin: 20px 0 15px 0; color: #555;">⏰ 24小时消费分布</h4>
            <div class="chart-container" id="hourlyChart"></div>
            
            <h4 style="margin: 20px 0 15px 0; color: #555;">📅 星期消费分布</h4>
            <div class="chart-container" id="weeklyChart"></div>
            
            <h4 style="margin: 20px 0 15px 0; color: #555;">🏷️ 类别偏好分析</h4>
            <div class="chart-container" id="categoryChart"></div>
            
            <h4 style="margin: 20px 0 15px 0; color: #555;">📊 消费趋势与预测</h4>
            <div class="chart-container" id="trendChart"></div>
        </div>
    </div>

    <script src="js/api.js"></script>
    <script src="js/notification.js"></script>
    <script src="js/analysis.js"></script>
</body>
</html>

